package com.nbgroup.web.Appraise;

import com.nbgroup.entity.Appraise;
import com.nbgroup.entity.Exhibition;
import com.nbgroup.entity.Literature;
import com.nbgroup.service.Appraise.AppraiseService;
import com.nbgroup.service.ExhibitionService;
import com.nbgroup.service.LiteratureService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by wyt on 2018/8/27.
 */
@RestController
@RequestMapping("/appraise")
public class AppraiseController {

    @Autowired
    AppraiseService appraiseService;
    @Autowired
    LiteratureService literatureService;
    @Autowired
    ExhibitionService exhibitionService;

    @RequestMapping(value = "/getAppraises", method = RequestMethod.GET)
    public List<Appraise> getAppraises(Integer lid) {
        return appraiseService.getAppraises(0, lid);
    }


    @RequestMapping(value = "/findOne", method = RequestMethod.POST)
    public Appraise findOne(Integer lid) {
        Appraise one = appraiseService.findOne(lid);
        Literature oneForLiterature = literatureService.findOneForLiterature(one.getLid());
        Exhibition oneForExhibition = exhibitionService.findOneForExhibition(oneForLiterature.getExhibtionId());
        one.setExhibitionName(oneForExhibition.getExhibitionName()+"-"+oneForLiterature.getLiteratureTitle());
        return one;
    }
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    public Integer del(Integer id) {
     try {
         appraiseService.del(id);
         return 0;
     }catch (Exception e){
         return 1;
     }
    }

    @RequestMapping(value = "/delAll", method = RequestMethod.POST)
    public Integer delAll(String id) {
        try {
            String[] split = id.split(",");
            for (String s:split) {
                appraiseService.del(Integer.parseInt(s));
            }
            return 0;
        }catch (Exception e){
            return 1;
        }
    }


    //zzp修改评价审核状态
    @RequestMapping(value = "/changeSts", method = RequestMethod.GET)
    public String changeSts(Integer id, Integer sts) {
        try {
            String s = appraiseService.changeSts(id, sts);
            return s;
        } catch (Exception e) {
            e.printStackTrace();
            return "-1";
        }
    }
}
